package com.yunzheng.modoules.enrollAndLogin.enroll.dao;

import com.yunzheng.utils.DBUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class MemberDaoImpl implements MemberDao{
    private static Connection connection;

    @Override
    public String queryTerm(String name) throws Exception {
        String term = null;
        connection = DBUtils.getCon();
        String sql = "select * from yunzi where name = ?;";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1,name);
        ResultSet resultSet = preparedStatement.executeQuery();
        if (resultSet.next()){
            term = resultSet.getString("term");
        }
        DBUtils.release(resultSet,preparedStatement,connection);
        return term;
    }

    @Override
    public String queryDirect(String name) throws Exception {
        String direction = null;
        connection = DBUtils.getCon();
        String sql = "select * from yunzi where name = ?;";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1,name);
        ResultSet resultSet = preparedStatement.executeQuery();
        if (resultSet.next()){
            direction = resultSet.getString("direction");
        }
        DBUtils.release(resultSet,preparedStatement,connection);
        return direction;
    }

    @Override
    public int queryId(String name) throws Exception {
        int id = 0;
        connection = DBUtils.getCon();
        String sql = "select id from yunzi where name = ?;";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1,name);
        ResultSet resultSet = preparedStatement.executeQuery();
        if (resultSet.next()){
            id = resultSet.getInt("id");
        }
        DBUtils.release(resultSet,preparedStatement,connection);
        return id;

    }
}

